# -*- coding:utf-8 -*- #

# ----------------------------------------------------------
# Name:        ML.first
# Description: 第一个机器学习脚本：线性回归预测
# Authon:      syl
# Date:        2021-01-11
# ----------------------------------------------------------

import numpy as np

tlist = np.array(
    [194.45, 320.66, 458.77, 545.47, 665.47, 773.17, 870.82, 951.98, 1055.05, 1147.93, 1257.53, 1332.53, 1400.93,
     1471.28, 1527.52,
     1548.36, 1637.90, 1689.26, 1746.52, 1801.80, 1860.96, 1909.71, 1962.91, 2012.39, 2060.24, 2113.95, 2162.37,
     2220.20, 2266.13, 2309.35,
     2349.48, 2399.81, 2446.41, 2494.00, 2539.48, 2584.60, 2626.78, 2666.55, 2706.29, 2752.33, 2790.95, 2831.52,
     2873.17, 2913.97,
     2954.55, 2996.15, 3036.22, 3078.12, 3117.67, 3153.55, 3195.43, 3236.28, 3275.55, 3311.98, 3351.45
     ])
clist = np.array([(i + 1) * 1000 for i in range(len(tlist))])

from sklearn.model_selection import train_test_split

x_train, x_test, y_train, y_test = train_test_split(clist, tlist,test_size=0.1)

x_train = x_train.reshape(-1, 1)
y_train = y_train.reshape(-1, 1)

from sklearn.linear_model import LinearRegression

model = LinearRegression()
model.fit(x_train, y_train)

t = model.predict([[2820000]])
h = int(t[0][0])/3600
print(h)
